// pages/ordservice/ordservice.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seconds: 0,
    time: '00:00:00',
    cost: 0,
    set:''
  },
  //拨打电话
  start_call: function () {
    wx.makePhoneCall({
      phoneNumber: '1340000' //仅为示例，并非真实的电话号码
    })
  },
  //问题反馈
  start_problem:function(){
    app.navTo('../problem/problem')
  },
  start_over: function () {
    var that = this;
    var times = that.data.time;
    clearInterval(that.data.set)    
    that.setData({
      times: that.data.time
    })
    wx.showToast({
      title: '完成服务',
      duration: 3000,
      icon: 'success',
      success:function(){
        app.navTo('../clearing/clearing')
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    that.setData({
      set:setInterval(function(){
        that.timing()
      },1000)
    })
  },
  timing:function() {
    let that = this;
    // console.log(that.data.seconds)
    var seconds = that.data.seconds
    that.setData({
      seconds: seconds + 1
    });
    formatSeconds(this)
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    let that = this;
    that.setData({
      set: setInterval(function () {
        that.timing()
      }, 1000)
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    let that = this;
    that.setData({
      set: setInterval(function () {
        that.timing()
      }, 1000)
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})

function formatSeconds(that) {
  var mins = 0, hours = 0, seconds = that.data.seconds, time = ''  
  if (seconds < 60) {

  } else if (seconds < 3600) {
    mins = parseInt(seconds / 60)
    seconds = seconds % 60
  } else {
    mins = parseInt(seconds / 60)
    seconds = seconds % 60
    hours = parseInt(mins / 60)
    mins = mins % 60
  }  
  that.setData({
    time: formatTime(hours) + ':' + formatTime(mins) + ':' + formatTime(seconds)   
  });  
}
function formatTime(num) {  
  if (num < 10)
    return '0' + num
  else
    return num + ''
}
// function charging(that) {
//   if (that.data.seconds < 600) {
//     cost = 1
//   }
// }